package org.me.marble;

import java.nio.*;

import java.util.ArrayList;

/**
 *
 * @author tungi
 */

public class BufferFactory{

    public static FloatBuffer MakeFloatBuffer(ArrayList<Float> list){
        float[] listArray=new float[list.size()];
        for(int i=0;i<list.size();++i)
            listArray[i]=list.get(i);
        return MakeFloatBuffer(listArray);
    }

    public static FloatBuffer MakeFloatBuffer(float[] array){
        ByteBuffer vbb=ByteBuffer.allocateDirect(array.length*4);
        vbb.order(ByteOrder.nativeOrder());
        FloatBuffer buffer=vbb.asFloatBuffer();
        buffer.put(array);
        buffer.position(0);
        return buffer;
    }

    public static ByteBuffer MakeByteBuffer(int[] array){
        ByteBuffer bb=ByteBuffer.allocateDirect(array.length*4);
        bb.order(ByteOrder.BIG_ENDIAN);
        IntBuffer ib=bb.asIntBuffer();
        ib.put(array);
        ib.position(0);
        bb.position(0);
        return bb;
    }
}
